package com.link.base.base.common.service;

import com.link.base.base.common.dao.mybatis.mapper.ScrollImgMapper;
import com.link.base.base.common.model.ScrollImg;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.basic.service.ServiceException;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/9 10:15
 * @version 1.0
 */

@Service
public class ScrollImgServiceImpl extends BasicServiceImpl<ScrollImg> implements ScrollImgService {

    @Resource
    private ScrollImgMapper scrollImgMapper;

    @Override
    public BasicMapper<ScrollImg> getBasicMapper() {
        return scrollImgMapper;
    }

    @Override
    public void beforInsert(ScrollImg entity) throws Exception {
        super.beforInsert(entity);
        if (StringUtils.isBlank(entity.getType())) {
            throw new ServiceException("COMMON-005");
        }
        if (StringUtils.isBlank(entity.getActiveFlag())) {
            throw new ServiceException("COMMON-006");
        }
    }

    /**
     *  更新图片ID
     * @param entity
     * @throws Exception
     */
    @Override
    public void imgIdUpdate(ScrollImg entity) throws Exception {
        scrollImgMapper.imgIdUpdate(entity);
    }

    /**
    *  根据当前的登录类型判断筛选的轮播图
    * @param  entity
    * @author Lizt
    * @date 2018/10/16
    */
    @Override
    public List<ScrollImg> queryAllActive(ScrollImg entity) throws Exception {
        if (StringUtils.isBlank(entity.getScope())) {
            switch (entity.getLoginType()) {
                case GUIDE_APP:
                    entity.setScope("Guide");
                    break;
                case MP:
                    entity.setScope("MiniProgram");
                    break;
                case DMS_APP:
                    entity.setScope("dms");
                    break;
                default:
                    break;
            }
        }
        return scrollImgMapper.queryAllActive(entity);
    }
}
